package com.yuwei.movie.demo

import androidx.lifecycle.viewModelScope
import com.yuwei.common.mvi.BaseViewModel
import com.yuwei.database.RoomDBUtils.getVideoDao
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.launch

class MovieViewModel : BaseViewModel<MovieApiService, MovieIntent>() {
    override fun handleIntent(intent: MovieIntent) {
        viewModelScope.launch {
            when (intent) {
                is MovieIntent.getMovieList -> {
                    httpRequest(apiService.getVideoType(), "getMovieType")
                }
                is MovieIntent.getVideoRecommend ->{
                    httpRequest(apiService.getVideoRecommend(intent.page,intent.pagesize),"getMovieRecommend")
                }
                is MovieIntent.getVideoList ->{
                    httpRequest(apiService.getVideoList(intent.page,intent.pagesize,intent.typeid),"getMovieRecommend")
                }
                is MovieIntent.insertVideo ->{
                    roomRequest({getVideoDao().insert(intent.videoParamEntity)},"insertVideo")
                }
            }
        }
    }
}